home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 106_01.zip / PRVLIB.C < prev    next >
Text File  |  1993-06-26  |  3KB  |  125 lines

  1. /*------------------------------------------------------------------*/
  2. /*                                                                  */
  3. /*  This is a library of private routines for use with BDS C prog-  */
  4. /*  grams.  The comment lines preceding each entry are intended     */
  5. /*  to give a sufficient explanation of the routine that follows.   */
  6. /*  To link any of these routines to a BDS C program, merely name   */
  7. /*  PRVLIB as a argument following the name of the main program in  */
  8. /*  the CLINK command line.                                         */
  9. /*                                                                  */
  10. /*------------------------------------------------------------------*/
  11.  
  12.  
  13. /*
  14.     Move k bytes from blk1 to blk2.  
  15.     The two blocks may overlap.
  16.     Since k must be positive, this routine is limited to
  17.     moving blocks less than 32k in length.
  18.     Added by M. Goldberg, 25-DEC-79. 
  19. */
  20. movblk(blk1, blk2, k) 
  21.     char *blk1, *blk2;
  22.     int k;
  23.     {
  24.     int m,n,t,u;
  25.     if ((k <= 0) || (!(t = blk1 - blk2))) return;
  26.     if (t > 0) {m = 0; n = k;}
  27.     else {m = 1 - k; n = 1;}
  28.     for (t = m; t < n; ++t) 
  29.         {
  30.         u = (t < 0 ? -t : t);
  31.         *(blk2 + u) = *(blk1 + u);
  32.         }
  33.     }
  34.  
  35.  
  36. /*
  37.     ASCII counter -- increments a field of ASCII digits by one. 
  38.     Arguments are a pointer to the field (high-order digit) 
  39.     and the length of the field. 
  40.     The routine stops if it encounters a non-digit character 
  41.     in the field.
  42.     Added by M. Goldberg, 25-DEC-79. 
  43. */
  44. asc_cntr(addr, len) 
  45.     char *addr;
  46.     int len;
  47.     {
  48.     addr += len;
  49.     do 
  50.         {
  51.         if (!isdigit(*(--addr))) break;
  52.         if (++(*addr) <= '9') break;
  53.         *addr = '0';
  54.         }
  55.         while (--len);
  56.     }
  57.  
  58.  
  59. /*
  60.     Sends a CR-LF pair to the CP/M LIST device.
  61.     Added by M. Goldberg, 25-DEC-79. 
  62. */
  63. #define    LF          0x0A
  64. #define    CR          0x0D
  65. newline()
  66.     {
  67.     bdos(5, CR); bdos(5,LF);
  68.     }
  69.  
  70.  
  71. /* 
  72.     Sends a line of dashes to the CP/M LIST device.
  73.     The argument is the number of dashes in the line.
  74.     Added by M. Goldberg, 16-FEB-80.
  75. */ 
  76. dashes(n) 
  77.     char n;
  78.     {
  79.     char i;
  80.     for (i = 0; i < n; ++i) bdos(5, '-');
  81.     newline();
  82.     }
  83.  
  84.  
  85. /*
  86.     Causes a block of bytes to be displayed at the CP/M
  87.     console device as a vector of two-digit hex numbers.
  88.     Spaces are used to separate one hex number from another.
  89.     It was written as a debug aid, that is, to be used to take 
  90.     a snapshot of a memory during program execution.
  91.  
  92.     The arguments are: 
  93.         blkp = a pointer to the beginning of the memory block 
  94.     and
  95.         n = the number of bytes in the block.
  96.  
  97.     Added by M. Goldberg, 6-MAR-80.
  98. */
  99. puthx(blkp, n)
  100.     char *blkp;
  101.     int n;
  102.     {
  103.     char c;
  104.     while (n-- > 0)
  105.         {
  106.         prhd(((c = *blkp++) & 0xF0) >> 4);
  107.         prhd(c & 0x0F);
  108.         putchar(' ');
  109.         }
  110.     }
  111.  
  112.  
  113. /*
  114.     Outputs a message to the CP/M console device and 
  115.     stops the program.  The argument is a pointer to the
  116.     message string.
  117.     Added by M. Goldberg, 15-MAR-80.
  118. */
  119. stop(msg)
  120.     char msg[];
  121.     {
  122.     puts(msg);
  123.     exit();
  124.     }
  125.